//
//  ByFootBallHandle.m
//  caipiao_ios
//
//  Created by mc on 2018/7/21.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByFootBallHandle.h"
#import "JSONKit.h"
#import "ByBasketBallHandle.h"


@implementation ByFootBallHandle

+ (NSMutableArray *)getNoSaleDataWith:(NSDictionary *)dic WithCount:(NSInteger)count;{
    NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:1];
    for (NSInteger i = 0; i < count; i++) {
        ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dic];
        netModel.selected = NO;
        netModel.isNoSale = YES;
        netModel.valueString = @"未开售";
        [dataArray addObject:netModel];
    }
    return dataArray;
}


+ (NSMutableArray *)getFinalSpfDataWithDic:(NSDictionary *)dic WithOtherModel:(ByNetModel *)HAD_Model{
    
    
    
    NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:1];
    
    for (NSInteger i = 0; i < 3; i++) {
        
        ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dic];
        
        netModel.selected = NO;
        netModel.single = HAD_Model.single;
        netModel.timeString = HAD_Model.timeString;
        netModel.play_type = @"3010";
        if (i == 0) {
            
            netModel.title = @"主胜";
            
            netModel.valueString = HAD_Model.h;
            
            netModel.numKey = @"3";
            
        }else if (i == 1){
            
            netModel.title = @"平";
            
            netModel.valueString = HAD_Model.d;
            
            netModel.numKey = @"1";
            
        }else if (i == 2){
            
            netModel.title = @"客胜";
            
            netModel.valueString = HAD_Model.a;
            
            netModel.numKey = @"0";
            
        }
        
        [dataArray addObject:netModel];
        
    }
    
    return dataArray;
    
}





+ (NSMutableArray *)getFinalRspfDataWithDic:(NSDictionary *)dic WithOtherModel:(ByNetModel *)HHAD_Model{
    
    
    
    NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:1];
    
    for (NSInteger i = 0; i < 3; i++) {
        
        ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dic];
        
        netModel.selected = NO;
        netModel.fixedodds = HHAD_Model.fixedodds;
        netModel.single = HHAD_Model.single;
        netModel.timeString = HHAD_Model.timeString;
        netModel.play_type = @"3006";
        if (i == 0){
            
            netModel.title = @"主胜";
            
            netModel.valueString = HHAD_Model.h;
            
            netModel.numKey = @"3";
            
        }else if (i == 1){
            
            netModel.title = @"平";
            
            netModel.valueString = HHAD_Model.d;
            
            netModel.numKey = @"1";
            
        }else if (i == 2){
            
            netModel.title = @"客胜";
            
            netModel.valueString = HHAD_Model.a;
            
            netModel.numKey = @"0";
            
        }
        
        [dataArray addObject:netModel];
        
    }
    
    return dataArray;
    
}



+ (NSMutableArray *)getFinalGoalsDataWithDic:(NSDictionary *)dic WithOtherModel:(ByNetModel *)TTG_Model{
    

    NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:1];
    for (NSInteger i = 0; i < 8; i++) {
        ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dic];
        netModel.selected = NO;
        NSArray *titlsArray = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7+"];
        netModel.title = [NSString stringWithFormat:@"%@",titlsArray[i]];
        netModel.single = TTG_Model.single;
        netModel.timeString = TTG_Model.timeString;
        netModel.play_type = @"3008";
        if (TTG_Model) {
            
            if (i == 0) {
                
                netModel.valueString = TTG_Model.s0;
                
            }else if (i == 1){
                
                netModel.valueString = TTG_Model.s1;
                
            }else if (i == 2){
                
                netModel.valueString = TTG_Model.s2;
                
            }else if (i == 3){
                
                netModel.valueString = TTG_Model.s3;
                
            }else if (i == 4){
                
                netModel.valueString = TTG_Model.s4;
                
            }else if (i == 5){
                
                netModel.valueString = TTG_Model.s5;
                
            }else if (i == 6){
                
                netModel.valueString = TTG_Model.s6;
                
            }else if (i == 7){
                
                netModel.valueString = TTG_Model.s7;
                
            }
            netModel.numKey = [NSString stringWithFormat:@"%ld", i];
            
        }
        
        [dataArray addObject:netModel];
        
    }
    
    return dataArray;
    
}


+ (NSMutableArray *)getFinalHalfAllDataWithDic:(NSDictionary *)dic WithOtherModel:(ByNetModel *)HAFU_Model{
    
    NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:1];
    for (NSInteger i = 0; i < 9; i++) {
        
        ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dic];
        
        netModel.selected = NO;
        
        NSArray *titlsArray = @[@"胜胜",@"胜平",@"胜负",@"平胜",@"平负",@"负胜",@"负平",@"负负",@"平平"];;
        
        netModel.title = [NSString stringWithFormat:@"%@",titlsArray[i]];
        netModel.single = HAFU_Model.single;
        netModel.timeString = HAFU_Model.timeString;
        netModel.play_type = @"3009";
        if (HAFU_Model) {
            
            if (i == 0) {
                
                netModel.valueString = HAFU_Model.hh;
                netModel.numKey = @"33";
                
            }else if (i == 1){
                
                netModel.valueString = HAFU_Model.hd;
                netModel.numKey = @"31";
                
            }else if (i == 2){
                
                netModel.valueString = HAFU_Model.ha;
                netModel.numKey = @"30";
            }else if (i == 3){
                
                netModel.valueString = HAFU_Model.dh;
                netModel.numKey = @"13";
            }else if (i == 4){
                
                netModel.valueString = HAFU_Model.da;
                netModel.numKey = @"10";
            }else if (i == 5){
                
                netModel.valueString = HAFU_Model.ah;
                netModel.numKey = @"03";
            }else if (i == 6){
                
                netModel.valueString = HAFU_Model.ad;
                netModel.numKey = @"01";
            }else if (i == 7){
                
                netModel.valueString = HAFU_Model.aa;
                netModel.numKey = @"00";
            }else if (i == 8){
                
                netModel.valueString = HAFU_Model.dd;
                netModel.numKey = @"11";
            }
            
        }
        
        [dataArray addObject:netModel];
        
    }
    
    
    
    
    return dataArray;
}

+ (NSMutableArray *)getFinalScoresDataWithDic:(NSDictionary *)dic WithOtherModel:(ByNetModel *)CRS_Model{
    
     NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:1];
     NSArray * titlesArray = @[@"1:0",@"2:0",@"2:1",@"3:0",@"3:1",@"3:2",@"4:0",@"4:1",@"4:2",@"5:0",@"5:1",@"5:2",@"胜其他",@"0:0",@"1:1",@"2:2",@"3:3",@"平其他",@"0:1",@"0:2",@"1:2",@"0:3",@"1:3",@"2:3",@"0:4",@"1:4",@"2:4",@"0:5",@"1:5",@"2:5",@"负其他"];
    
    for (NSInteger i = 0; i < titlesArray.count; i++) {
        
        ByNetModel *netModel = [[ByNetModel alloc] initContentWithDic:dic];
        netModel.selected = NO;
        netModel.title = titlesArray[i];
        netModel.single = CRS_Model.single;
        netModel.timeString = CRS_Model.timeString;
        netModel.play_type = @"3007";
        if (i == 0) {
            netModel.valueString = CRS_Model.score0100;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"10";
        }else if (i == 1){
            netModel.valueString = CRS_Model.score0200;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"20";
        }else if (i == 2){
            netModel.valueString = CRS_Model.score0201;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"21";
        }else if (i == 3){
            netModel.valueString = CRS_Model.score0300;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"30";
        }else if (i == 4){
            netModel.valueString = CRS_Model.score0301;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"31";
        }else if (i == 5){
            netModel.valueString = CRS_Model.score0302;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"32";
        }else if (i == 6){
            netModel.valueString = CRS_Model.score0400;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"40";
        }else if (i == 7){
            netModel.valueString = CRS_Model.score0401;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"41";
        }else if (i == 8){
            netModel.valueString = CRS_Model.score0402;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"42";
        }else if (i == 9){
            netModel.valueString = CRS_Model.score0500;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"50";
        }else if (i == 10){
            netModel.valueString = CRS_Model.score0501;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"51";
        }else if (i == 11){
            netModel.valueString = CRS_Model.score0502;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"52";
        }else if (i == 12){
            netModel.valueString = CRS_Model.score_h;
            netModel.spfKey = @"3";
            netModel.scoreKey = @"99";
        }else if (i == 13){
            netModel.valueString = CRS_Model.score0000;
            netModel.spfKey = @"1";
            netModel.scoreKey = @"00";
        }else if (i == 14){
            netModel.valueString = CRS_Model.score0101;
            netModel.spfKey = @"1";
            netModel.scoreKey = @"11";
        }else if (i == 15){
            netModel.valueString = CRS_Model.score0202;
            netModel.spfKey = @"1";
            netModel.scoreKey = @"22";
        }else if (i == 16){
            netModel.valueString = CRS_Model.score0303;
            netModel.spfKey = @"1";
            netModel.scoreKey = @"33";
        }else if (i == 17){
            netModel.valueString = CRS_Model.score_d;
            netModel.spfKey = @"1";
            netModel.scoreKey = @"99";
        }else if (i == 18){
            netModel.valueString = CRS_Model.score0001;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"01";
        }else if (i == 19){
            netModel.valueString = CRS_Model.score0002;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"02";
        }else if (i == 20){
            netModel.valueString = CRS_Model.score0102;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"12";
        }else if (i == 21){
            netModel.valueString = CRS_Model.score0003;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"03";
        }else if (i == 22){
            netModel.valueString = CRS_Model.score0103;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"13";
        }else if (i == 23){
            netModel.valueString = CRS_Model.score0203;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"23";
        }else if (i == 24){
            netModel.valueString = CRS_Model.score0004;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"04";
        }else if (i == 25){
            netModel.valueString = CRS_Model.score0104;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"14";
        }else if (i == 26){
            netModel.valueString = CRS_Model.score0204;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"24";
        }else if (i == 27){
            netModel.valueString = CRS_Model.score0005;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"05";
        }else if (i == 28){
            netModel.valueString = CRS_Model.score0105;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"15";
        }else if (i == 29){
            netModel.valueString = CRS_Model.score0205;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"25";
        }else if (i == 30){
            netModel.valueString = CRS_Model.score_a;
            netModel.spfKey = @"0";
            netModel.scoreKey = @"99";
        }
        netModel.numKey = [NSString stringWithFormat:@"%@(%@)",netModel.spfKey,netModel.scoreKey];
        
        [dataArray addObject:netModel];
        
    }
    
    
    
    return dataArray;
}


// 0 混合投注 1 胜平负 2.让球胜平负 3 总进球 4 比分 5半全场
+ (NSMutableArray *)getFootBallOriginalDataWithCount:(NSInteger)count WithItems:(NSMutableArray *)array WithType:(NSInteger)type{
    
    NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:1];
    for (NSInteger i = 0; i < count; i++) {
        ByNetModel *netModel = [[ByNetModel alloc] init];
        netModel.selected = NO;
        netModel.type = type;
        
        if (type == 1) {
            netModel.valueString = @"1.84";
            if (i % 3 == 0) {
                netModel.title = @"主胜";
            }else if (i % 3 == 1){
                netModel.title = @"平";
            }else if (i % 3 == 2){
                netModel.title = @"客胜";
            }
        }else if (type == 2){
            
            netModel.valueString = @"1.84";
            if (i % 3 == 0) {
                netModel.title = @"主胜";
            }else if (i % 3 == 1){
                netModel.title = @"平";
            }else if (i % 3 == 2){
                netModel.title = @"客胜";
            }
            
        }else if (type == 3){
            
            netModel.valueString = @"13.00";
            NSArray *dataArray = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7+"];
            netModel.title = [NSString stringWithFormat:@"%@(13.0)",dataArray[i]];
            
        }else if (type == 4){
            
            netModel.valueString = @"8.00";
            NSArray * dataArray = @[@"1:0",@"2:0",@"2:1",@"3:0",@"3:1",@"3:2",@"4:0",@"4:1",@"4:2",@"5:0",@"5:1",@"5:2",@"胜其他",@"0:0",@"1:1",@"2:2",@"3:3",@"平其他",@"0:1",@"0:2",@"1:2",@"0:3",@"1:3",@"2:3",@"0:4",@"1:4",@"2:4",@"0:5",@"1:5",@"2:5",@"负其他"];
            netModel.title = dataArray[i];
            
        }else if (type == 5){
            
            NSArray *dataArray = @[@"胜胜",@"胜平",@"胜负",@"平胜",@"平负",@"负胜",@"负平",@"负负",@"平平"];
            netModel.valueString = @"2.90";
            netModel.title = dataArray[i];
            
        }
        netModel.value = i;
        [dataArray addObject:netModel];
    }
    return dataArray;
}


+ (NSMutableArray *)getFootBallSelectedDataWithArray:(NSArray *)array{
    
    NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:1];
    for (NSMutableArray *sectionArray in array) {
        for (NSMutableArray *indexArray in sectionArray) {
            for (ByNetModel *netModel in indexArray) {
                if (netModel.selected) {
                    [tempArray addObject:netModel];
                }
            }
        }
    }
    return tempArray;

}





//取消数据选择
+ (void )deselectFootBallDataWithArray:(NSMutableArray *)selectedArray{
    for (NSMutableArray *sectionArray in selectedArray) {
        for (NSMutableArray *rowArray in sectionArray) {
            for (ByNetModel *netModel in rowArray) {
                netModel.selected = NO;
            }
        }
    }
    
    
}

//取消数据选择
+ (void)deselectBallDataWithArray:(NSMutableArray *)selectedArray WithRemainStr:(NSString *)str{
    
    for (NSMutableArray *sectionArray in selectedArray) {
        for (NSMutableArray *rowArray in sectionArray) {
            ByNetModel *netModel =  [rowArray firstObject];
            if (![str containsString:netModel.ID]) {
                for (ByNetModel *netModel in rowArray) {
                    netModel.selected = NO;
                }
            }
            
        }
    }
    
}


+ (NSMutableArray *)getFootBallAllRowDataArrayWithKey:(NSString *)key WithArray:(NSMutableArray *)array{
    for (NSMutableArray *sectionArray in array) {
        for (NSMutableArray *rowArray in sectionArray) {
            for (ByNetModel *netModel in rowArray) {
                if ([netModel.ID isEqualToString:key]) {
                    return rowArray;
                }
            }
        }
    }
    
    return nil;
}


+ (NSInteger)getSingleCountWithArray:(NSMutableArray *)array{
    NSInteger count = 0;
    for (ByNetModel *netModel in array) {
        for (ByNetModel *model in netModel.selectedSpfArray) {
            if (model.single.integerValue > 0) {
                count = count + 1;
            }
        }
        
        for (ByNetModel *model in netModel.selectedRSpfArray) {
            if (model.single.integerValue > 0) {
                count = count + 1;
            }
        }
        
        for (ByNetModel *model in netModel.selectedGoalsArray) {
            if (model.single.integerValue > 0) {
               count = count + 1;
            }
        }
        
        for (ByNetModel *model in netModel.selectedScoresArray) {
            if (model.single.integerValue > 0) {
               count = count + 1;
            }
        }
        
        for (ByNetModel *model in netModel.selectedHalfAllArray) {
            if (model.single.integerValue > 0) {
                count = count + 1;
            }
        }
    }
    return count;
}


//注数计算
+ (NSInteger)getCountWithSelectedCount:(NSInteger)selectedCount withNumber:(NSInteger)number withArray:(NSMutableArray *)array{
    
    //单关
    if (number == 1) {
        return [self getSingleCountWithArray:array];
    }
    
    NSMutableArray *countAry = [NSMutableArray arrayWithCapacity:1];
    for (ByNetModel *netModel in array) {
         NSInteger count = netModel.selectedSpfArray.count +
         netModel.selectedRSpfArray.count +
         netModel.selectedGoalsArray.count +
         netModel.selectedScoresArray.count +
         netModel.selectedHalfAllArray.count;
         [countAry addObject:@(count)];
    }
    
    if (selectedCount == number){
        
        NSInteger count = 1;
        for (NSNumber *number in countAry) {
            count = count * number.integerValue;
        }
        return count;
        
    }else{
        
     NSInteger count = 0;
     NSMutableArray *combinArray = [self getCombinWithCountAry:countAry withNumber:number];
     SLog(@"combinArray = %@", combinArray);
     for (NSArray *array in combinArray) {
         NSInteger value = 1;
         for (NSNumber *number in array) {
             value = value *number.integerValue;
         }
         count = count + value;
     }
        return count;
    }
    

    
}


+ (NSInteger)getBasketBallSingleCountWithArray:(NSMutableArray *)array{
    NSInteger count = 0;
    for (ByNetModel *netModel in array) {
        for (ByNetModel *model in netModel.sfSelectedArray) {
            if (model.single.integerValue > 0) {
                count = count + 1;
            }
        }
        
        for (ByNetModel *model in netModel.rsfSelectedArray) {
            if (model.single.integerValue > 0) {
                count = count + 1;
            }
        }
        
        for (ByNetModel *model in netModel.bigSmallSelectedArray) {
            if (model.single.integerValue > 0) {
                count = count + 1;
            }
        }
        
        for (ByNetModel *model in netModel.sfcSelectedArray) {
            if (model.single.integerValue > 0) {
                count = count + 1;
            }
        }
        
    }
    return count;
}

//注数计算
+ (NSInteger)getBasketBallCountWithSelectedCount:(NSInteger)selectedCount withNumber:(NSInteger)number withArray:(NSMutableArray *)array{
    
    //单关
    if (number == 1) {
        return [self getBasketBallSingleCountWithArray:array];
    }
    
    NSMutableArray *countAry = [NSMutableArray arrayWithCapacity:1];
    for (ByNetModel *netModel in array) {
        NSInteger count = netModel.sfSelectedArray.count +
        netModel.rsfSelectedArray.count +
        netModel.bigSmallSelectedArray.count +
        netModel.sfcSelectedArray.count;
        [countAry addObject:@(count)];
    }
    
    if (selectedCount == number){
        
        NSInteger count = 1;
        for (NSNumber *number in countAry) {
            count = count * number.integerValue;
        }
        return count;
        
    }else{
        
        NSInteger count = 0;
        NSMutableArray *combinArray = [self getCombinWithCountAry:countAry withNumber:number];
        SLog(@"combinArray = %@", combinArray);
        for (NSArray *array in combinArray) {
            NSInteger value = 1;
            for (NSNumber *number in array) {
                value = value *number.integerValue;
            }
            count = count + value;
        }
        return count;
    }
    
    
    
}



+ (NSMutableArray *)getCombinWithCountAry:(NSMutableArray *)countAry withNumber:(NSInteger)number{
    NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:1];
    NSMutableArray *resultArray = [NSMutableArray arrayWithCapacity:1];
    for (int i = 0; i < number; i++) {
        [tempArray addObject:@"0"];
    }
    
    NSInteger n = countAry.count;
    NSInteger m = number;
    for (NSInteger i = n; i >= m ; --i) {
        [tempArray replaceObjectAtIndex:m-1 withObject:[countAry objectAtIndex:i-1]];
        [self combination:i-1 in:m-1 WithCountAry:countAry WithTempAry:tempArray WithResultAry:resultArray];
    }
    return resultArray;
}

+ (void)combination:(NSInteger)n in:(NSInteger)m WithCountAry:(NSMutableArray *)countAry WithTempAry:(NSMutableArray *)tempArray WithResultAry:(NSMutableArray *)resultArray{
    if (m == 0) {
        [resultArray addObject:[NSArray arrayWithArray:tempArray]];
        return;
    }
    for (NSInteger i = n; i >= m ; --i) {
        [tempArray replaceObjectAtIndex:m-1 withObject:[countAry objectAtIndex:i-1]];
        [self combination:i-1 in:m-1 WithCountAry:countAry WithTempAry:tempArray WithResultAry:resultArray];
    }
}


//构造足球投注
+ (NSMutableDictionary *)getFootBallNumWithSelectedData:(NSMutableArray *)dataArray WithType:(NSInteger)type;{
    
    NSMutableDictionary *numDic = [NSMutableDictionary dictionary];
    for (ByNetModel *netModel in dataArray) {
        NSString *key = [NSString stringWithFormat:@"%@%@",netModel.netModel.timeString,netModel.netModel.num_type];
        key =  [key stringByReplacingOccurrencesOfString:@"-" withString:@""];
        NSMutableDictionary *valueDic = [NSMutableDictionary dictionary];
        if (netModel.selectedSpfArray.count > 0) {
            NSMutableDictionary *spfDic = [self getFootBall3010ValueWith:netModel.selectedSpfArray];
            NSLog(@"spfDic = %@", spfDic);
            [valueDic setObject:spfDic forKey:@"3010"]; //设置胜平负数据
        }
        
        if (netModel.selectedRSpfArray.count > 0) {
            NSMutableDictionary *rspfDic = [self getFootBall3010ValueWith:netModel.selectedRSpfArray];
            NSLog(@"rspfDic = %@", rspfDic);
            [valueDic setObject:rspfDic forKey:@"3006"]; //设置让球胜平负
        }
        
        if (netModel.selectedScoresArray.count > 0) {
            NSMutableDictionary *scoresDic = [self getFootBall3007ValueWithArray:netModel.selectedScoresArray];
            NSLog(@"scoresDic = %@", scoresDic);
            [valueDic setObject:scoresDic forKey:@"3007"]; //全场比分
        }
        
        if (netModel.selectedGoalsArray) {
            NSMutableDictionary *goalsDic = [self getFootBall3008ValueWithArray:netModel.selectedGoalsArray];
            NSLog(@"goalsDic = %@", goalsDic);
            [valueDic setObject:goalsDic forKey:@"3008"];
        }
        
        if (netModel.selectedHalfAllArray) {
            NSMutableDictionary *halfAllDic = [self getFootBall3009ValueWithArray:netModel.selectedHalfAllArray];
            NSLog(@"halfAllDic = %@", halfAllDic);
            [valueDic setObject:halfAllDic forKey:@"3009"];
        }
        
        [numDic setObject:valueDic forKey:key];
    }
    
    
    return numDic;
    
}

+ (NSMutableDictionary *)getFootBall3009ValueWithArray:(NSArray *)dataArray{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    for (ByNetModel *netModel in dataArray) {
        [dic setObject:netModel.single forKey:@"single"];
        [dic setObject:netModel.valueString forKey:netModel.numKey];
        
    }
    return dic;
}


+ (NSMutableDictionary *)getFootBall3010ValueWith:(NSArray *)dataArray{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    for (ByNetModel *netModel in dataArray) {
        [dic setObject:netModel.single forKey:@"single"];
        if ([netModel.title isEqualToString:@"主胜"]) {
            [dic setObject:netModel.valueString forKey:@"3"];
        }else if ([netModel.title isEqualToString:@"平"]){
            [dic setObject:netModel.valueString forKey:@"1"];
        }else if ([netModel.title isEqualToString:@"客胜"]){
            [dic setObject:netModel.valueString forKey:@"0"];
        }
    }
    return dic;
}

+ (NSMutableDictionary *)getFootBall3007ValueWithArray:(NSArray *)dataArray{
    
    NSMutableDictionary *scoresDic = [NSMutableDictionary dictionary];
    NSMutableDictionary *dic3 = [NSMutableDictionary dictionary];
    NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
    NSMutableDictionary *dic0 = [NSMutableDictionary dictionary];
    
    for (ByNetModel *netModel in dataArray) {
       [scoresDic setObject:netModel.single forKey:@"single"];
        if ([netModel.spfKey isEqualToString:@"3"]) {
            [dic3 setObject:netModel.valueString forKey:netModel.scoreKey];
        }else if ([netModel.spfKey isEqualToString:@"1"]) {
            [dic1 setObject:netModel.valueString forKey:netModel.scoreKey];
        }else  if ([netModel.spfKey isEqualToString:@"0"]) {
            [dic0 setObject:netModel.valueString forKey:netModel.scoreKey];
        }
    }
    NSArray *array3 = [dic3 allKeys];
    NSArray *array0 = [dic0 allKeys];
    NSArray *array1 = [dic1 allKeys];
    if (array3.count > 0) {
         [scoresDic setObject:dic3 forKey:@"3"];
    }
    if (array0.count > 0) {
        [scoresDic setObject:dic0 forKey:@"0"];
    }
    
    if (array1.count > 0) {
        [scoresDic setObject:dic1 forKey:@"1"];
    }
    return scoresDic;
}


+ (NSMutableDictionary *)getFootBall3008ValueWithArray:(NSArray *)dataArray{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    NSMutableDictionary *goalsDic = [NSMutableDictionary dictionary];
    for (ByNetModel *netModel in dataArray) {
        [dic setObject:netModel.single forKey:@"single"];
        if ([netModel.title isEqualToString:@"7+"]) {
            [goalsDic setObject:netModel.valueString forKey:@"7"];
        }else{
            [goalsDic setObject:netModel.valueString forKey:netModel.title];
        }
    }
    
    [dic setObject:goalsDic forKey:@"goals"];
    return dic;
}


+ (NSString *)getFootBallFreePassWithArray:(NSMutableArray *)dataArray{
    
    
    NSString *free_pass = @"";
    for (NSNumber *number in dataArray) {
        if (free_pass.length == 0) {
            free_pass = [NSString stringWithFormat:@"%@", number];
        }else{
          free_pass = [NSString stringWithFormat:@"%@,%@",free_pass,number];
        }
        
    }
    return free_pass;
}


+ (BOOL)isOrNotClickWithSpfData:(NSMutableArray *)spfArray rspfData:(NSMutableArray *)rspfArray goalsData:(NSMutableArray *)goalsArray halfAllData:(NSMutableArray *)halfAllArray scoresData:(NSMutableArray *)scoresArray WithType:(NSInteger )type WithIndexPath:(NSIndexPath *)indexPath{
    
    BOOL canClick = YES;
    NSMutableArray *halfAllSectionAry = [halfAllArray objectAtIndex:indexPath.section];
    NSMutableArray *goalsSectionAry = [goalsArray objectAtIndex:indexPath.section];
    NSMutableArray *scoresSectionAry = [scoresArray objectAtIndex:indexPath.section];
    NSMutableArray *sectionAry1 = [spfArray objectAtIndex:indexPath.section];
    NSMutableArray *sectionAry2 = [rspfArray objectAtIndex:indexPath.section];
    
    NSMutableArray *indexAry1 = [sectionAry1 objectAtIndex:indexPath.row];
    NSMutableArray *indexAry2 = [sectionAry2 objectAtIndex:indexPath.row];
    NSMutableArray *halfAllRowAry1 = [halfAllSectionAry objectAtIndex:indexPath.row];
    NSMutableArray *goalsRowAry1 = [goalsSectionAry objectAtIndex:indexPath.row];
    NSMutableArray *scoresRowAry1 = [scoresSectionAry objectAtIndex:indexPath.row];
    
    NSMutableArray *selectedArray1 = [ByLotteryAlgorithmHandle getSelectedDataWithArray:[indexAry1 copy]];
    NSMutableArray *selectedArray2 = [ByLotteryAlgorithmHandle getSelectedDataWithArray:[indexAry2 copy]];
    NSMutableArray *selectedArray3 = [ByLotteryAlgorithmHandle getSelectedDataWithArray:[halfAllRowAry1 copy]];
    NSMutableArray *selectedArray4 = [ByLotteryAlgorithmHandle getSelectedDataWithArray:[goalsRowAry1 copy]];
    NSMutableArray *selectedArray5 = [ByLotteryAlgorithmHandle getSelectedDataWithArray:[scoresRowAry1 copy]];
    
    
    // 0 混合投注 1 胜平负 2.让球胜平负 3 总进球 4 比分 5半全场
    if (type == 1) {
        if (selectedArray2.count + selectedArray3.count + selectedArray4.count + selectedArray5.count > 0) {
            [ByCoreToolAlert showOnlyText:@"混合过关一场比赛只能选择一种玩法"];
            return NO;
        }
    }else if (type == 2){
        if (selectedArray1.count + selectedArray3.count + selectedArray4.count + selectedArray5.count > 0) {
            [ByCoreToolAlert showOnlyText:@"混合过关一场比赛只能选择一种玩法"];
            return NO;
        }
    }else if (type == 3){
        if (selectedArray1.count + selectedArray2.count + selectedArray3.count + selectedArray5.count > 0) {
            [ByCoreToolAlert showOnlyText:@"混合过关一场比赛只能选择一种玩法"];
            return NO;
        }
    }else if (type == 4){
        if (selectedArray1.count + selectedArray2.count + selectedArray3.count + selectedArray4.count > 0) {
            [ByCoreToolAlert showOnlyText:@"混合过关一场比赛只能选择一种玩法"];
            return NO;
        }
    }else if (type == 5){
        if (selectedArray1.count + selectedArray2.count + selectedArray4.count + selectedArray5.count > 0) {
            [ByCoreToolAlert showOnlyText:@"混合过关一场比赛只能选择一种玩法"];
            return NO;
        }
    }
    
    
    return canClick;
}

+ (BOOL)isOrNotClickWithRowSpfData:(NSMutableArray *)spfArray  goalsData:(NSMutableArray *)goalsArray halfAllData:(NSMutableArray *)halfAllArray scoresData:(NSMutableArray *)scoresArray WithType:(NSInteger )type{
    
    
    BOOL canClick = YES;
    NSArray *spfArray1 = [spfArray subarrayWithRange:NSMakeRange(0, 3)];
    NSArray *spfArray2 = [spfArray subarrayWithRange:NSMakeRange(3, 3)];
    
    
    NSMutableArray *selectedArray1 = [ByLotteryAlgorithmHandle getSelectedDataWithArray:[spfArray1 copy]];
    NSMutableArray *selectedArray2 = [ByLotteryAlgorithmHandle getSelectedDataWithArray:[spfArray2 copy]];
    NSMutableArray *selectedArray3 = [ByLotteryAlgorithmHandle getSelectedDataWithArray:[halfAllArray copy]];
    NSMutableArray *selectedArray4 = [ByLotteryAlgorithmHandle getSelectedDataWithArray:[goalsArray copy]];
    NSMutableArray *selectedArray5 = [ByLotteryAlgorithmHandle getSelectedDataWithArray:[scoresArray copy]];
    
    
    // 0 混合投注 1 胜平负 2.让球胜平负 3 总进球 4 比分 5半全场
    if (type == 1) {
        if (selectedArray2.count + selectedArray3.count + selectedArray4.count + selectedArray5.count > 0) {
            [ByCoreToolAlert showOnlyText:@"混合过关一场比赛只能选择一种玩法"];
            return NO;
        }
    }else if (type == 2){
        if (selectedArray1.count + selectedArray3.count + selectedArray4.count + selectedArray5.count > 0) {
            [ByCoreToolAlert showOnlyText:@"混合过关一场比赛只能选择一种玩法"];
            return NO;
        }
    }else if (type == 3){
        if (selectedArray1.count + selectedArray2.count + selectedArray3.count + selectedArray5.count > 0) {
            [ByCoreToolAlert showOnlyText:@"混合过关一场比赛只能选择一种玩法"];
            return NO;
        }
    }else if (type == 4){
        if (selectedArray1.count + selectedArray2.count + selectedArray3.count + selectedArray4.count > 0) {
            [ByCoreToolAlert showOnlyText:@"混合过关一场比赛只能选择一种玩法"];
            return NO;
        }
    }else if (type == 5){
        if (selectedArray1.count + selectedArray2.count + selectedArray4.count + selectedArray5.count > 0) {
            [ByCoreToolAlert showOnlyText:@"混合过关一场比赛只能选择一种玩法"];
            return NO;
        }
    }
    
    
    return canClick;
    
    
}


//有单关
+ (BOOL)hasSingleWithArray:(NSMutableArray *)dataArray{
    
    for (ByNetModel *netModel in dataArray) {
        for (ByNetModel *model in netModel.selectedSpfArray) {
            if (model.single.integerValue > 0) {
                return YES;
            }
        }
        
        for (ByNetModel *model in netModel.selectedRSpfArray) {
            if (model.single.integerValue > 0) {
                return YES;
            }
        }
        
        for (ByNetModel *model in netModel.selectedGoalsArray) {
            if (model.single.integerValue > 0) {
                return YES;
            }
        }
        
        for (ByNetModel *model in netModel.selectedScoresArray) {
            if (model.single.integerValue > 0) {
                return YES;
            }
        }
        
        for (ByNetModel *model in netModel.selectedHalfAllArray) {
            if (model.single.integerValue > 0) {
                return YES;
            }
        }
    }
    return NO;
}

//一场比赛 是否只有单关
+ (BOOL)oneGameIsOnlyHasSinglePass:(NSMutableArray *)dataArray{
    for (ByNetModel *model in dataArray) {
        if (model.single.integerValue == 0) {
            return NO;
        }
    }
    return YES;
}



+ (NSString *)getFootBallFreePassStringWithString:(NSString *)string{
    NSString *freePassString = @"";
    NSArray *array = [string componentsSeparatedByString:@","];
    NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:1];
    for (NSString *string in array) {
        NSString *subString = [string substringToIndex:1];
        if (subString.integerValue == 1) {
            [dataArray addObject:@"单关"];
        }else{
            [dataArray addObject:[NSString stringWithFormat:@"%@串1",subString]];
        }
    }
    
    freePassString = [dataArray componentsJoinedByString:@" "];
    return freePassString;
}

+ (NSMutableDictionary *)getFootBallGameResultWithPlan:(NSString *)plan{
    NSMutableDictionary *resultDic = [NSMutableDictionary  dictionaryWithCapacity:1];
    
    NSMutableDictionary *dic = [plan mutableObjectFromJSONString];
    NSArray *allKeys = [dic allKeys];
    for (int i = 0; i < allKeys.count; i++) {
        NSString *key  = [allKeys objectAtIndex:i];
        NSDictionary *sectionDic = [dic objectForKey:key];
        NSString *resultString = [ByFootBallHandle getOneFootBallGameResultStingWithDictonary:sectionDic];
        [resultDic setObject:resultString forKey:key];
    }
    return resultDic;
}

//{
//    3006 =     {
//        0 = "1.78";
//        3 = "3.85";
//        single = 0;
//    };
//    3007 =     {
//        3 =         {
//            21 = "8.00";
//        };
//        single = 1;
//    };
//    3008 =     {
//        goals =         {
//            2 = "2.95";
//        };
//        single = 1;
//    };
//    3009 =     {
//        33 = "2.85";
//        single = 1;
//    };
//    3010 =     {
//        0 = "4.37";
//        3 = "1.80";
//        single = 0;
//    };
//}


+ (NSString *)getOneFootBallGameResultStingWithDictonary:(NSDictionary *)dic{
    NSString *resultSting = @"";
    NSArray *keys = [dic allKeys];
    NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:1];
    for (NSString *key in keys) {
        //胜平负
        if (key.integerValue == 3010){
            NSDictionary *valueDic = [dic objectForKey:key];
            NSArray *valueKeys = [valueDic allKeys];
            for (NSString *value in valueKeys) {
                if (![value isEqualToString:@"single"]) {
                    if (value.integerValue == 3) {
                        [dataArray addObject:[NSString stringWithFormat:@"主胜(%@)",valueDic[@"3"]]];
                    }else if (value.integerValue == 1){
                        [dataArray addObject:[NSString stringWithFormat:@"平(%@)",valueDic[@"1"]]];
                    }else if (value.integerValue == 0){
                        [dataArray addObject:[NSString stringWithFormat:@"主负(%@)",valueDic[@"0"]]];
                    }
                }
                
            }
            
        }else if (key.integerValue == 3006){ // 让球胜平负
            NSDictionary *valueDic = [dic objectForKey:key];
            NSArray *valueKeys = [valueDic allKeys];
            for (NSString *value in valueKeys) {
                if (![value isEqualToString:@"single"]) {
                    if (value.integerValue == 3) {
                        [dataArray addObject:[NSString stringWithFormat:@"让主胜(%@)",valueDic[@"3"]]];
                    }else if (value.integerValue == 1){
                        [dataArray addObject:[NSString stringWithFormat:@"让平(%@)",valueDic[@"1"]]];
                    }else if (value.integerValue == 0){
                        [dataArray addObject:[NSString stringWithFormat:@"让主负(%@)",valueDic[@"0"]]];
                    }
                }
              
            }
            
        }else if (key.integerValue == 3007){
            
            NSDictionary *valueDic = [dic objectForKey:key];
            
            NSArray *array3 = [valueDic[@"3"] allKeys];
            NSArray *array1 = [valueDic[@"1"] allKeys];
            NSArray *array0 = [valueDic[@"0"] allKeys];
            
            if (array3.count > 0) {
                for (NSString *value in array3) {
                    
                    NSString *valueString = [valueDic[@"3"] objectForKey:value];
                    
                    if (value.integerValue == 99) {
                        [dataArray addObject:[NSString stringWithFormat:@"胜其他(%@)",valueString]];
                    }else{
                        NSMutableString *str = [[NSMutableString alloc] initWithString:value];
                        [str insertString:@":" atIndex:1];
                        [dataArray addObject:[NSString stringWithFormat:@"%@(%@)",str,valueString]];
                    }
                }
            }
            
            if (array1.count > 0) {
                for (NSString *value in array1) {
                    NSString *valueString = [valueDic[@"1"] objectForKey:value];
                    
                    if (value.integerValue == 99) {
                        [dataArray addObject:[NSString stringWithFormat:@"平其他(%@)", valueString]];
                    }else{
                        NSMutableString *str = [[NSMutableString alloc] initWithString:value];
                        [str insertString:@":" atIndex:1];
                         [dataArray addObject:[NSString stringWithFormat:@"%@(%@)",str,valueString]];
                    }
                }
            }
            
           
            if (array0.count > 0) {
                for (NSString *value in array0) {
                    NSString *valueString = [valueDic[@"0"] objectForKey:value];
                    if (value.integerValue == 99) {
                        [dataArray addObject:[NSString stringWithFormat:@"负其他(%@)", valueString]];
                    }else{
                        NSMutableString *str = [[NSMutableString alloc] initWithString:value];
                        [str insertString:@":" atIndex:1];
                         [dataArray addObject:[NSString stringWithFormat:@"%@(%@)",str,valueString]];
                    }
                }
            }
            
            
            
        }else if (key.integerValue == 3008){
            
            NSDictionary *valueDic = [dic objectForKey:key];
            
            if ([valueDic[@"goals"] isKindOfClass:[NSDictionary class]]) {
                NSArray *valueKeys = [valueDic[@"goals"] allKeys];
                if (valueKeys.count > 0) {
                    for (NSString *value in valueKeys) {
                        NSString *valueString = [valueDic[@"goals"] objectForKey:value];
                        if ([value isEqualToString:@"7"]) {
                            [dataArray addObject:[NSString stringWithFormat:@"7+球(%@)",valueString]];
                        }else{
                            [dataArray addObject:[NSString stringWithFormat:@"%@球(%@)",value,valueString]];
                        }
                        
                    }
                }
            }
            
        }else if (key.integerValue == 3009){
            
            NSDictionary *valueDic = [dic objectForKey:key];
            NSArray *valueKeys = [valueDic allKeys];
            for (NSString *value in valueKeys) {
                if (![value isEqualToString:@"single"]) {
                    
                    NSString *valueString = [valueDic objectForKey:value];
                    
                    NSString *firstStr = [value substringWithRange:NSMakeRange(0, 1)];
                    NSString *lastStr = [value substringWithRange:NSMakeRange(1, 1)];
                    if ([firstStr isEqualToString:@"3"]) {
                        firstStr = @"胜";
                    }else if ([firstStr isEqualToString:@"0"]){
                        firstStr = @"负";
                    }else if ([firstStr isEqualToString:@"1"]){
                        firstStr = @"平";
                    }
                    
                    if ([lastStr isEqualToString:@"3"]) {
                        lastStr = @"胜";
                    }else if ([lastStr isEqualToString:@"0"]){
                        lastStr = @"负";
                    }else if ([lastStr isEqualToString:@"1"]){
                        lastStr = @"平";
                    }
                    
                    [dataArray addObject:[NSString stringWithFormat:@"%@%@(%@)",firstStr,lastStr,valueString]];
                    
                }
            }
            
        }
    }
    if (dataArray.count > 1) {
       return [dataArray componentsJoinedByString:@","];
    }else if (dataArray.count == 1){
        return  [dataArray firstObject];
    }

   return  resultSting;
}


+ (NSString *)getGameResultStringWithSaiDic:(NSDictionary *)dic{
    
    NSString *str;
    if ([dic isKindOfClass:[NSDictionary class]]){
        NSString *banquan = dic[@"banquan"];
        NSString *bf = dic[@"bf"];
        NSString *r = dic[@"r"];
        NSString *r_pv = dic[@"r.pv"];
        NSString *s_pv = dic[@"s.pv"];
        NSString *spf = dic[@"spf"];
        NSString *tot = dic[@"tot"];
        NSString *t_pv = dic[@"t.pv"];
        
        NSString *value1 = [self getStringWithValue:spf Value:s_pv];
        NSString *value2 = [NSString stringWithFormat:@"让%@",[self getStringWithValue:r Value:r_pv]];
        NSString *firstStr = [banquan substringWithRange:NSMakeRange(0, 1)];
        NSString *lastStr = [banquan substringWithRange:NSMakeRange(1, 1)];
        if ([firstStr isEqualToString:@"3"]) {
            firstStr = @"胜";
        }else if ([firstStr isEqualToString:@"0"]){
            firstStr = @"负";
        }else if ([firstStr isEqualToString:@"1"]){
            firstStr = @"平";
        }
        
        if ([lastStr isEqualToString:@"3"]) {
            lastStr = @"胜";
        }else if ([lastStr isEqualToString:@"0"]){
            lastStr = @"负";
        }else if ([lastStr isEqualToString:@"1"]){
            lastStr = @"平";
        }
        NSString *value3 = [NSString stringWithFormat:@"%@%@",firstStr,lastStr];
        NSString *value4 = [NSString stringWithFormat:@"%@球", tot];
        NSString *value5 = [NSString stringWithFormat:@"%@", bf];
        return [NSString stringWithFormat:@"%@,%@,%@,%@,%@",value1,value2,value3,value4,value5];
        
    }
    return @"未开奖";

}


+ (NSString *)getStringWithValue:(NSString *)value Value:(NSString *)value1{
    NSString *str;
    if (value.integerValue == 3) {
          str = @"主胜";
    }else if (value.integerValue == 1){
          str = @"平";
    }else if (value.integerValue == 0){
          str = @"主负";
    }
    NSString *string = [NSString stringWithFormat:@"%@(%@)", str,value1];
    return string;
}


+ (NSString *)getFootBallGameResultWithOnePlan:(NSString *)plan{
    NSArray *array = [plan mutableObjectFromJSONString];
    NSMutableDictionary *dic = [array firstObject];
    NSArray *allKeys = [dic allKeys];
    for (int i = 0; i < allKeys.count; i++) {
        NSString *key  = [allKeys objectAtIndex:i];
        if (![key isEqualToString:@"is_prize"]) {
            NSDictionary *sectionDic = [dic objectForKey:key];
            NSString *resultString = [ByFootBallHandle getOneFootBallGameResultStingWithDictonary:sectionDic];
            return resultString;
        }
    }
    
    return @"";
    
}


// 根据选中数据 得到id字符串
+ (NSString *)getCurrentSelectedGameIDStringWithArray:(NSMutableArray *)dataArray{
    NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:1];
    for (ByNetModel *netModel in dataArray) {
        [tempArray addObject:netModel.netModel.ID];
    }
    NSString *str =  [tempArray componentsJoinedByString:@"-"];
    return str;
}

@end
